<template>
	<mxq-router-layout>
		<div class="line-list">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<span>常规巡视</span>
				</div>
				<div slot="headerRight">
					<i class="iconfont icon-shouye"/>
					<!-- <van-icon class="home" name="home"/> -->
				</div>
			</Head>
			<van-tabs v-model="active" sticky>
				<van-tab :title="'未完成' + '('+wwcNum+')'">
					<xs-list
						:list = "taskListsWWC"
						:listLeftImg="listLeftImg"
						:listTitle="listTitle"
						@listClick="listClick($event)"/>
				</van-tab>
				<van-tab :title="'已完成' + '('+ywcNum+')'">
					<xs-list
						:list = "taskListsYWC"
						:listLeftImg="listLeftImg"
						:listTitle="listTitle"
						@listClick="listClick($event)"/>
				</van-tab>
			</van-tabs>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '../../../components/head';
import XsList from '../../../components/xs-list';
import IconWks from '../../../assets/img/changguixunshi/icon_wks.png';
import IconJxz from '../../../assets/img/changguixunshi/icon_jxz.png';
import IconYwc from '../../../assets/img/changguixunshi/icon_ywc.png';
import { getJson,callData } from '../../../axios/axios';
import {
	Icon,
	Tab,
	Tabs,
	Popup,
	Dialog
} from 'vant'

export default {
    components: {
		[Icon.name]: Icon,
		[Tab.name]:Tab,
		[Tabs.name]:Tabs,
		[Popup.name]:Popup,
		Head,
        XsList
	},
	data() {
		return {
			active: '',									//未完成、已完成切换选中
			wwcNum: 0,									//未完成任务数
			ywcNum: 0,									//已完成任务数
			taskListsWWC: [],							//未完成任务列表数据
			taskListsYWC: [],							//已完成任务列表数据
			listLeftImg: [IconWks,IconJxz,IconYwc],		//列表左侧图标
			listTitle: ['','杆塔数：','未巡视：'],//列表自定义key
			importantInform: false,						//是否显示重要告知
			importInform: '',							//重要告知弹框内容
			params: this.$route.query					//获取地址栏参数
		}
	},
	mounted() {
		this.getNum();			//未完成数、已完成数
		this.getTaskListWWC(); //未完成列表数据
		this.getTaskListYWC()	//已完成列表数据
    },
    methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			this.$router.push({name:"index"})
		},
		// 任务列表点击事件
		listClick(e){
			console.log('endtime',e);
			if(e.todo==0){
				/* if(e.data.KEY_INFO){
					this.importantInform = true;
					this.importInform = e.data.KEY_INFO;
				} */
				if(e.data.KEY_INFO){
	        		Dialog.alert({
					  title: '重要告知',
					  message: e.data.KEY_INFO
					}).then(() => {
					  // on close
					});
	        	}
			}
			// 获取任务结束时间
			else if(e.todo==1 && e.data.STATUS == 2){
				this.$router.push({
					name: 'cgxs_gantaXunshi',
					query: {
						xsId: e.data.ID,
						page: 0,
						size: 800,
						index: this.params.index,	//taskType任务类型
						taskEndTime: e.data.REAL_END_TIME,
						taskStatus:e.data.STATUS
					}
				})
			}
			else {
				let query = {
					xsId: e.data.ID,
					taskStatus:e.data.STATUS,
					page: 0,
					size: 800,
					index: this.params.index	//taskType任务类型
				};
				console.log('query',query);
				this.$router.push({
					name: 'cgxs_gantaXunshi',
					query: query
				})
			}
		},
		getNum() { // 获取未完成、已完成数
			callData('/xsTaskServer/ZcXsTowerTask/appZcXsTasksNum', 'get', {}).then(res => {
				this.wwcNum = res.data[0].WWC; //未完成数
				this.ywcNum = res.data[0].YWC; //已完成数
			})
		},
		// 获取未完成任务列表数据
		getTaskListWWC() {
			var params ={};
			params.page = 0;
			params.size = 800;
			params.status = 0;
			callData('/xsTaskServer/ZcXsTowerTask/appZcXsTasks', 'get', params).then(res => {
				var xsData = res.data.content;
				xsData.forEach((item,index) => {
					item.line = item.TASK_NAME; //线路名称
					item.gtnum = item.TOTAL; //杆塔总数
					item.wxsnum = item.WX; //未巡杆塔数
					item.date = item.PLAN_END_TIME; //计划结束时间
					item.id = item.ID;
					if(item.KEY_INFO == null){
						item.alarm = false
					}else{
						item.alarm = true
					}
					// 状态判断
					if (item.STATUS == 0) {
						item.statusName = '未开始';
						item.status = item.STATUS;
						item.cname="btn_status";
						item.cname1="btn_statusNo";
					}else if (item.STATUS == 1) {
						item.statusName = '进行中';
						item.cname="btn_status1";
						item.cname1="btn_statusNo";
						item.status = item.STATUS;
					}
				});
				this.taskListsWWC = xsData;
			})
		},
		// 获取已完成任务列表数据
		getTaskListYWC() {
			var params ={};
			params.page = 0;
			params.size = 800;
			params.status = 1;
			callData('/xsTaskServer/ZcXsTowerTask/appZcXsTasks', 'get', params).then(res => {
				var xsYWCData = res.data.content;
				xsYWCData.forEach((item,index) => {
					item.line = item.TASK_NAME; //线路名称
					item.gtnum = item.TOTAL; //杆塔总数
					item.wxsnum = item.WX; //未巡杆塔数
					item.date = item.PLAN_END_TIME; //计划结束时间
					item.id = item.ID;
					if(item.KEY_INFO == null){
						item.alarm = false
					}else{
						item.alarm = true
					}
					// 状态判断
					if(item.STATUS == 2) {
						item.statusName = '已完成';
						item.status = item.STATUS;
						item.cname="btn_status2";
						item.cname1="btn_statusNo";
					}
				});
				this.taskListsYWC = xsYWCData;
			})
		}
	}
}
</script>
